import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import plotly.express as px
import plotly.graph_objects as go
from IPython.display import Markdown, display
def printmd(string):
display(Markdown(string))
# Importing data
df = pd.read_csv('/etlstage/PEE_joint/NUS_modules/CS5340/group_data/GME_stock.csv')
df.head()
df.info()
df['date'] = pd.to_datetime(df['date'])
df.set_index('date',inplace=True)
df.head()
# Plotting the open, close, high, low, volume and adjusted close value for the term of 12 months
fig = px.line(df, x=df.index, y=df.columns,
title='Plot of values for a 12 month period')
fig.update_xaxes(
dtick="M12",
tickformat="%b\n%Y")
fig.update_xaxes(rangeslider_visible=True)
fig.show()
# Plotting the total amount traded
df['total_amount_traded'] = df['open_price']*df['volume']
fig = px.line(df, x=df.index, y=df.total_amount_traded,
title='Plot of total amount traded = open_price * volume')
fig.update_xaxes(
rangeslider_visible=True,
rangeselector=dict(
buttons=list([
dict(count=1, label="1m", step="month", stepmode="backward"),
dict(count=6, label="6m", step="month", stepmode="backward"),
dict(count=1, label="1y", step="year", stepmode="backward"),
dict(step="all")
])
)
)
fig.show()
# Plotting the moving average for the opening price
df['MA_256'] = df['open_price'].rolling(256).mean()
df[['open_price','MA_256']].plot(figsize=(16,8))